<?php

$sql = "SELECT
	tg_name,
	FROM_UNIXTIME(sg_time,'%Y-%m-%d') AS sgtime,
	count(*) AS count
FROM
	cmf_taobao
WHERE
qualified = '合格'
GROUP BY
	tg_name,
	FROM_UNIXTIME(sg_time, '%Y-%m-%d')
ORDER BY tg_name desc,sg_time asc";

//$reslut = Db:name("table_name")->query($sql);


//以上代码只是让你看下我的 result 数据结构[ '渠道名 tg_name','日期 time','当天总量 count']

$allTotal = 0;
foreach($result as $k=>$v){
	$result[$k]['price'] = price($v['count']);
	$allTotal = $allTotal +　$result[$k]['price'];
}

//根据 条件算金额 3  6  9 和 >9
function price($total){
	$price = [3,3,3,6,6,6,9,9,9];
	if($total >= count($price)){
		$price = array_pad($price,$total,9);
	}
	if($total < count($price)){
		$price = array_slice($price,0,$total);
	}
	var_dump($price);
	return array_sum($price);
}
